<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no,viewprot-fit:contain" />
    <meta name="misapplication-tap-highlight" content="no" />
    <meta name="HandheldFriendly" content="true" />
    <meta name="MobileOptimized" content="320" />
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <title>抽奖加载中...</title>
    <link rel="stylesheet" type="text/css" href="css/common.css" />
    <link rel="stylesheet" type="text/css" href="css/all.css" />
    <style>
    html,
    body {
        background: url("img/loading.jpg") no-repeat center;
        -webkit-background-size: 100% 100%;
        background-size: 100% 100%;
    }
    /*#canvas{
            margin: auto;
            padding-top: 2.5rem;
            width:10rem;
            height: 10rem;
        }*/
    </style>
</head>

<body>
    <div class="loading">
        <div id="wave" class="wave"><span id="proNum">0%</span></div>
    </div>
    <div class="tishiTxt">抽奖加载中...</div>
    <input type="hidden" id="sheng">
    <input type="hidden" id="shi">
    <iframe id="geoPage" width="100%" style="display: none" height="30%" frameborder=0 scrolling="no" src="https://apis.map.qq.com/tools/geolocation?key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77&referer=myapp&effect=zoom"></iframe>
</body>
<script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/layer/layer.js" type="text/javascript" charset="utf-8"></script>
<!--<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=0cqi5xRBogs5HnXstxpGYHIUb0Z9Eufj"></script>-->
<!--<script charset="utf-8" src="http://map.qq.com/api/js?v=2.exp&key=BOLBZ-47MKK-IFEJN-ASVY6-RGXL3-SKB4I"></script>-->
<script charset="utf-8" src="https://3gimg.qq.com/lightmap/components/geolocation/geolocation.min.js "></script>
<!--<script type="text/javascript" src="js/convertor.js"></script>-->
<script src="js/basic.js" type="text/javascript" charset="utf-8"></script>
<script src="js/md5.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
var wave = (function() {
    var ctx;
    var waveImage;
    var canvasWidth;
    var canvasHeight;
    var needAnimate = false;

    function init(callback) {
        var wave = document.getElementById('wave');
        var canvas = document.createElement('canvas');
        if (!canvas.getContext) return;
        ctx = canvas.getContext('2d');
        canvasWidth = wave.offsetWidth;
        canvasHeight = wave.offsetHeight;
        canvas.setAttribute('width', canvasWidth);
        canvas.setAttribute('height', canvasHeight);
        wave.appendChild(canvas);
        waveImage = new Image();
        waveImage.onload = function() {
            waveImage.onload = null;
            callback();
        }
        waveImage.src = 'img/wave.png';
    }

    function animate() {
        var waveX = 0;
        var waveY = 0;
        var proNum = 0;
        var waveX_min = -203;
        var waveY_max = canvasHeight * 1.1;
        var requestAnimationFrame =
            window.requestAnimationFrame ||
            window.mozRequestAnimationFrame ||
            window.webkitRequestAnimationFrame ||
            window.msRequestAnimationFrame ||
            function(callback) {
                window.setTimeout(callback, 1000 / 60);
            };

        function loop() {
            ctx.clearRect(0, 0, canvasWidth, canvasHeight);
            if (!needAnimate) return;
            if (waveY < waveY_max) waveY += 1.5;
            if (waveX < waveX_min) waveX = 0;
            else waveX -= 3;
            ctx.globalCompositeOperation = 'source-over';
            ctx.beginPath();
            ctx.arc(canvasWidth / 2, canvasHeight / 2, canvasHeight / 2, 0, Math.PI * 2, true);
            ctx.closePath();
            ctx.fill();
            ctx.globalCompositeOperation = 'source-in';
            ctx.drawImage(waveImage, waveX, canvasHeight - waveY);
            requestAnimationFrame(loop);

            if (proNum == 101) {
                proNum = 100;
            } else {
                document.getElementById("proNum").innerHTML = proNum + "%";
            }
            proNum++
        }

        loop();
    }

    function start() {
        if (!ctx) return init(start);
        needAnimate = true;
        setTimeout(function() {
            if (needAnimate) animate();
        }, 500);
    }

    function stop() {
        needAnimate = false;
    }

    return { start: start, stop: stop };
}());

$(function() {
    wave.start();
});
// ip定位 百度地图结合淘宝
$.getJSON("http://ywym.chengxinyipin.com/getTaoIP.php", function(json) {
    alert(JSON.stringify(json.data.ip));
    /*var myprovince2 = json.data.region;
    var mycity2 = json.data.city;
    alert("您所在的城市是："+myprovince2+mycity2);*/
    $.ajax({
        url: 'http://api.map.baidu.com/location/ip?ak=0cqi5xRBogs5HnXstxpGYHIUb0Z9Eufj&ip=' + json.data.ip + '&callback=?',
        type: 'get',
        dataType: 'json',
        success: function(result) {
            console.log(result.content.address_detail);
            alert(JSON.stringify(result.content.address_detail));
        },
        error: function(result) {
            console.log(result);
        }
    })
});

// 腾讯地图 获取地址 方法 20180428 GPS
setTimeout(function() {
    window.addEventListener('message', function(event) {
        if (event) {
            var loc = event.data;
            var sheng = loc.province,
                shi = loc.city;
            var _server = server.loading;
            var _data = {
                path: GetQueryString("path"),
                i: GetQueryString("i"),
                "p": GetQueryString("p"),
                "sheng": sheng,
                "shi": shi
            };
            localStorage.setItem("path", GetQueryString("path"));
            localStorage.setItem("i", GetQueryString("i"));
            //扫码 请求
            $.post(_server, _data, function(res) {
                if (res.status == -1) {
                    if (res.info == "has_end") {
                        layer.alert(res.detail);
                        $(".tishiTxt").html(res.detail);
                    } else if (res.info == "path_error") {
                        console.log(res.info);
                    } else if (res.info == "is_ban") {
                        console.log(res.info);
                    } else {
                        layer.alert("此二维码,已失效!");
                        $(".tishiTxt").html("此二维码,已失效!");
                    }
                } else {
                    //生成随机数加密
                    var ranString = hex_md5(randomString());
                    localStorage.setItem("ranString", ranString);
                    //背景图存储
                    localStorage.setItem("bodyImg", host + res.data.activity_info.thumb);
                    cunchuImg.bodyImg = host + res.data.activity_info.thumb;
                    //is_egg  0是直接扫码 1是砸金蛋
                    if (res.data.activity_info.is_egg == 0) {
                        console.log(host + "index.php?g=App&m=App&a=singe_saoma_prize");
                        window.location.href = host + "index.php?g=App&m=App&a=singe_saoma_prize&ranString=" + ranString;
                    } else if (res.data.activity_info.is_egg == 1) {
                        window.location.href = host + "index.php?g=App&m=App&a=index&ranString=" + ranString + "&isEgg=" + res.data.activity_info.is_egg;
                    } else {
                        drawFrame();
                    }
                }
            }, "json");
        }
    }, false);
}, 0);


//百度地图 定位 20180428 定位不是很稳定 GPS
function getLocation() {
    var geolocation = new BMap.Geolocation();
    // 创建地理编码实例
    var myGeo = new BMap.Geocoder();
    geolocation.getCurrentPosition(function(r) {
        if (this.getStatus() == BMAP_STATUS_SUCCESS) {
            var pt = r.point;
            // 根据坐标得到地址描述
            myGeo.getLocation(pt, function(result) {
                if (result) {
                    var addComp = result.addressComponents;
                    var sheng = addComp.province,
                        shi = addComp.city;
                    var _server = server.loading;
                    var _data = {
                        path: GetQueryString("path"),
                        i: GetQueryString("i"),
                        "p": GetQueryString("p"),
                        "sheng": sheng,
                        "shi": shi
                    };
                    localStorage.setItem("path", GetQueryString("path"));
                    localStorage.setItem("i", GetQueryString("i"));
                    //扫码 请求
                    $.post(_server, _data, function(res) {
                        if (res.status == -1) {
                            if (res.info == "has_end") {
                                layer.alert("活动已经结束");
                                $(".tishiTxt").html("很遗憾，活动已经结束！");
                            } else if (res.info == "path_error") {
                                console.log(res.info);
                            } else if (res.info == "is_ban") {
                                console.log(res.info);
                            } else {
                                layer.alert("此二维码,已失效!");
                                $(".tishiTxt").html("此二维码,已失效!");
                            }
                        } else {
                            //生成随机数加密
                            var ranString = hex_md5(randomString());
                            localStorage.setItem("ranString", ranString);
                            //背景图存储
                            localStorage.setItem("bodyImg", host + res.data.activity_info.thumb);
                            cunchuImg.bodyImg = host + res.data.activity_info.thumb;
                            //is_egg  0是直接扫码 1是砸金蛋
                            if (res.data.activity_info.is_egg == 0) {
                                console.log(host + "index.php?g=App&m=App&a=singe_saoma_prize");
                                window.location.href = host + "index.php?g=App&m=App&a=singe_saoma_prize&ranString=" + ranString;
                            } else if (res.data.activity_info.is_egg == 1) {
                                window.location.href = host + "index.php?g=App&m=App&a=index&ranString=" + ranString + "&isEgg=" + res.data.activity_info.is_egg;
                            } else {
                                drawFrame();
                            }
                        }
                    }, "json");
                }
            });
        }
    });
}
</script>

</html>